﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class CompanyFisheryDetail : YuanlinUserControl,
        IReplyConverter<CompanyFisheryReply, GetOperation>
    {
        protected Repeater list;
        private CompanyFishery companyFishery;

        public YuanlinUser CompanyUser
        {
            get
            {
                string greenNum = UrlManager.Instance.GetParameterValue<string>(YuanlinParameterName.GreenNum);
                if (!string.IsNullOrEmpty(greenNum))
                {
                    Member member = MemberManager.GetMember(greenNum);
                    if (member != null)
                    {
                        return UserManager.GetUser(member.MemberId) as YuanlinUser;
                    }
                }
                return new YuanlinUser();
            }
        }
        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            requestBinders.Add(RequestHelper.BuildGetCompanyFisheryRequest(this));
        }

        private void BindData()
        {
            EntityList companyFisherys = new EntityList();
            if (companyFishery != null)
            {
                companyFisherys.Add(companyFishery);
            }

            list.DataSource = companyFisherys;
            list.DataBind();
        }
        public string GetAquacultureMethods(string ids)
        {
            string returnval = string.Empty;
            string[] strs = ids.Split(',');
            AquacultureMethod aquacultureMethod = null;
            foreach (string item in strs)
            {
                aquacultureMethod = BusinessManager.GetAquacultureMethod(Globals.ChangeType<int>(item));
                if (aquacultureMethod == null)
                {
                    continue;
                }
                returnval += "," + aquacultureMethod.Title;
            }
            if (returnval.Length > 0)
            {
                returnval = returnval.Substring(1);
            }
            return returnval;
        }
        public string GetAquacultureAttributes(string ids)
        {
            string returnval = string.Empty;
            string[] strs = ids.Split(',');
            AquacultureAttribute aquacultureAttribute = null;
            foreach (string item in strs)
            {
                aquacultureAttribute = BusinessManager.GetAquacultureAttribute(Globals.ChangeType<int>(item));
                if (aquacultureAttribute == null)
                {
                    continue;
                }
                returnval += "," + aquacultureAttribute.Title;
            }
            if (returnval.Length > 0)
            {
                returnval = returnval.Substring(1);
            }
            return returnval;
        }

        #region IReplyConverter<CompanyFisheryReply,GetOperation> Members

        public void ConvertReply(CompanyFisheryReply reply, GetOperation operation)
        {
            if (reply != null)
            {
                companyFishery = reply.Entity as CompanyFishery;

                if (!IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
